import { Modal } from 'ant-design-vue';
import { h, createVNode } from 'vue';
import { MdiInfo } from '@vben/icons';

/**
 * 将Antd的Modal.confirm封装为promise，方便在异步函数中调用。
 * @param content 提示内容
 * @param title 提示标题
 */

export function confirmModal(title: string, content: string) {
  return new Promise((resolve) => {
    Modal.confirm({
      // icon: createVNode(), // 创建空节点替换原有图标
      icon: null,
      title: createVNode(
        'span',
        {
          style: 'flex: 1; max-width: calc(100% - 34px); display: flex; align-items: center;',
        },
        [
          h(MdiInfo, { style: 'flex: none; margin-inline-end: 12px; font-size: 22px;' }),
          title, // 标题内容
        ]
      ),
      // content: createVNode('div', { style: 'margin-inline-start: 34px' }, content),
      content: createVNode(
        'div',
        { style: 'margin-inline-start: 34px' },
        content.split('\n').map((text, i) => h('div', { key: i, style: 'margin-bottom: 8px' }, text))
      ),
      onCancel() {
        resolve(false);
      },
      onOk() {
        resolve(true);
      },
    });
  });
}
